﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Drawing;
using System.Drawing.Imaging;

namespace StateManagement
{
    public partial class ApplicationObject : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        protected void buttonAddLoad_Click(object sender, EventArgs e)
        {
            Application.Lock();
            Application["Users"] = (int)Application["Users"] + 1;
            Application.UnLock();
        }

        protected override void OnPreRender(EventArgs e)
        {
            base.OnPreRender(e);
            if (Application["Users"] == null)
            {
                Application["Users"] = 0;
            }
            Response.Clear();

            Bitmap generatedImage = new Bitmap(200, 200);
            Graphics gr = Graphics.FromImage(generatedImage);
            gr.FillRectangle(Brushes.MediumSeaGreen, 0, 0, 200, 200);
            //gr.FillPie(Brushes.Yellow, 25, 25, 150, 150, 0, 45);
            //gr.FillPie(Brushes.Green, 25, 25, 150, 150, 45, 315);
            gr.DrawString(Application["Users"].ToString(), new Font("Arial", 16), new SolidBrush(Color.Black), 30.0F, 50.0F);
            // Set response header and write the image into response stream
            Response.ContentType = "image/gif";
            Response.AppendHeader("Content-Disposition",
               "attachment; filename=\"2010.gif\"");
            //generatedImage.Save(Response.OutputStream, ImageFormat.Gif);

        }
    }
}